package org.sith.taskrunner.gwt.client.event;

import com.google.gwt.event.shared.GwtEvent;
import org.sith.taskrunner.gwt.shared.proxy.UserEntityProxy;

public class UsersTableEvent extends GwtEvent<UsersTableEventHandler> {
    public static final Type<UsersTableEventHandler> TYPE = new Type<UsersTableEventHandler>();

    public UserEntityProxy getUserEntityProxy() {
        return userEntityProxy;
    }

    public void setUserEntityProxy(UserEntityProxy userEntityProxy) {
        this.userEntityProxy = userEntityProxy;
    }


    public enum EventType {
        USER_UPDATED,
        RELOAD_ALL_USERS,
    }


    private EventType eventType;
    private UserEntityProxy userEntityProxy;

    public UsersTableEvent(EventType eventType) {
        this.eventType = eventType;
    }

    @Override
    public Type<UsersTableEventHandler> getAssociatedType() {
        return TYPE;
    }

    @Override
    protected void dispatch(UsersTableEventHandler handler) {
        switch (eventType) {
            case USER_UPDATED: {
                handler.onUserUpdated(this);
            }
            break;
            case RELOAD_ALL_USERS: {
                handler.onUpdateAllUsers(this);
            }
            break;
            default: {
            }
        }
    }
}
